package mytest.wd;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test2 {
    public static void main(String[] args) throws Exception {
        String nowDate = "2025-02-28";

        if (!validateDateFormat(nowDate)) {
            System.out.println("false");
            return;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);

        try {
            dateFormat.parse(nowDate);
            System.out.println("success");
        } catch (ParseException e) {
            System.out.println("false");
        }
    }

    public static boolean validateDateFormat(String dateStr) {
        // 正则表达式，匹配四位数的年份、两位数的月份和两位数的日期，中间由短横线分隔
        String regex = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(dateStr);
        return matcher.matches();
    }


}
